import 'package:flutter/material.dart';

class AnimatedExample01Page extends StatefulWidget {
  const AnimatedExample01Page({super.key});

  @override
  State<AnimatedExample01Page> createState() => _AnimatedExample01PageState();
}

class _AnimatedExample01PageState extends State<AnimatedExample01Page> {
  bool flag = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Animated Example 01'),
      ),
      body: Stack(children: [
        ListView(
          children: const [
            ListTile(
              title: Text('Item 1'),
            ),
            ListTile(
              title: Text('Item 2'),
            ),
            ListTile(
              title: Text('Item 3'),
            ),
            ListTile(
              title: Text('Item 4'),
            ),
            ListTile(
              title: Text('Item 5'),
            ),
          ],
        ),
        AnimatedPositioned(
          curve: Curves.linearToEaseOut,
          top: flag ? 10 : 560,
          right: flag ? 10 : 300,
          duration: const Duration(seconds: 1, milliseconds: 500),
          child: Container(
            width: 60,
            height: 60,
            color: Colors.blue,
          ),
        ),
      ]),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            flag = !flag;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
